﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace UI.View.OwnerView.Part
{
    /// <summary>
    /// SelectOwer.xaml 的交互逻辑
    /// </summary>
    public partial class SelectOwer : UserControl
    {
        ViewModel.OwnerViewModel vm;
        Model.DataContext context = new Model.DataContext();
        public SelectOwer()
        {
            InitializeComponent();
            vm = DataContext as ViewModel.OwnerViewModel;

            vm.ListOwner = context.DB.Queryable<Model.Owner>().ToList();
        }

        private void Btn_Cancle_Click(object sender, RoutedEventArgs e)
        {
            vm.Dialog.Close();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if(vm.CurrOwner ==null)
            {
                HandyControl.Controls.Growl.WarningGlobal("请选择一位业主!");
                return;
            }

            if (vm.CurrRoom == null)
            {
                HandyControl.Controls.Growl.WarningGlobal("请选择房屋");
                return;
            }
            Model.DataContext context = new Model.DataContext();
            vm.CurrRoom.OwnerId = vm.CurrOwner.Id;
            vm.CurrRoom.OwnerName = vm.CurrOwner.Name;
            vm.CurrRoom.MoveInfoTime = DateTime.Now;
            context.DB.Updateable<Model.Rooms>(vm.CurrRoom).ExecuteCommand();

            vm.Dialog.Close();

            vm.ListRooms = context.DB.Queryable<Model.Rooms>().ToList();
        }
    }
}
